/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
 * CANN Open Software License Agreement Version 2.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

#include <iostream>
#include <fstream>
#include <vector>
#include <gtest/gtest.h>
#include "../../../op_host/resize_upsample_trilinear_tiling.h"
#include "tiling_context_faker.h"
#include "tiling_case_executor.h"

using namespace std;
using namespace ge;

class ResizeUpsampleTrilinearTiling : public testing::Test {
protected:
    static void SetUpTestCase()
    {
        std::cout << "ResizeUpsampleTrilinearTiling SetUp" << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "ResizeUpsampleTrilinearTiling TearDown" << std::endl;
    }
};

struct ResizeUpsampleTrilinearCompileInfo {
    uint32_t coreNum = 0;
    uint16_t socVersionType = 0;
};

TEST_F(ResizeUpsampleTrilinearTiling, upsample_trilinear3d_tiling_001)
{
    gert::StorageShape input_shape = {{1, 1, 4, 128, 128}, {1, 1, 4, 128, 128}};
    gert::StorageShape out_shape = {{1, 1, 12, 256, 256}, {1, 1, 12, 256, 256}};
    ResizeUpsampleTrilinearCompileInfo compileInfo = {48, 220};
    std::vector<int64_t> output_size = {12, 256, 256};
    gert::TilingContextPara tilingContextPara("ResizeUpsampleTrilinear",
        {{input_shape, ge::DT_FLOAT, ge::FORMAT_ND}},
        {{out_shape, ge::DT_FLOAT, ge::FORMAT_ND}},
        {gert::TilingContextPara::OpAttr(
             "output_size", Ops::Cv::AnyValue::CreateFrom<std::vector<int64_t>>(output_size)),
            gert::TilingContextPara::OpAttr("align_corners", Ops::Cv::AnyValue::CreateFrom<bool>(false)),
            gert::TilingContextPara::OpAttr("scales_d", Ops::Cv::AnyValue::CreateFrom<float>(0.0)),
            gert::TilingContextPara::OpAttr("scales_h", Ops::Cv::AnyValue::CreateFrom<float>(0.0)),
            gert::TilingContextPara::OpAttr("scales_w", Ops::Cv::AnyValue::CreateFrom<float>(0.0))},
            &compileInfo);
    uint64_t expectTilingKey = 3000;

    string expectTilingData =
        "4539628425446424576 207209802411 0 160 256 256 12 128 128 4 1 0 0 0 0 0 0 0 734439407616 342 1468878815403 "
        "734439407616 342 1468878815403 734439407616 342 1468878815403 734439407616 342 1468878815403 734439407616 342 "
        "1468878815403 734439407616 342 1468878815403 734439407616 342 1468878815403 734439407616 342 1468878815403 "
        "1464583848106 730144440831 2194728288597 1464583848106 730144440831 2194728288597 1464583848106 730144440831 "
        "2194728288597 1464583848106 730144440831 2194728288597 1464583848106 730144440831 2194728288597 1464583848106 "
        "730144440831 2194728288597 1464583848106 730144440831 2194728288597 1464583848106 730144440831 2194728288597 "
        "0 68719476736 68719476752 137438953504 206158430240 206158430256 274877907008 343597383744 343597383760 "
        "412316860512 481036337248 481036337264 549755814016 618475290752 618475290768 687194767520 755914244256 "
        "755914244272 824633721024 893353197760 893353197776 962072674528 1030792151264 1030792151280 64424509455 "
        "133143986191 133143986207 201863462959 270582939695 270582939711 339302416463 408021893199 408021893215 "
        "476741369967 545460846703 545460846719 614180323471 682899800207 682899800223 751619276975 820338753711 "
        "820338753727 889058230479 957777707215 957777707231 1026497183983 1095216660719 1095216660735 0 68719476736 "
        "68719476752 137438953504 206158430240 206158430256 274877907008 343597383744 343597383760 412316860512 "
        "481036337248 481036337264 549755814016 618475290752 618475290768 687194767520 755914244256 755914244272 "
        "824633721024 893353197760 893353197776 962072674528 1030792151264 1030792151280 64424509455 133143986191 "
        "133143986207 201863462959 270582939695 270582939711 339302416463 408021893199 408021893215 476741369967 "
        "545460846703 545460846719 614180323471 682899800207 682899800223 751619276975 820338753711 820338753727 "
        "889058230479 957777707215 957777707231 1026497183983 1095216660719 1095216660735 8589934592 3 12884901890 "
        "8589934592 3 12884901890 8589934592 3 12884901890 8589934592 3 12884901890 8589934592 3 12884901890 "
        "8589934592 3 12884901890 8589934592 3 12884901890 8589934592 3 12884901890 12884901890 8589934596 17179869187 "
        "12884901890 8589934596 17179869187 12884901890 8589934596 17179869187 12884901890 8589934596 17179869187 "
        "12884901890 8589934596 17179869187 12884901890 8589934596 17179869187 12884901890 8589934596 17179869187 "
        "12884901890 8589934596 17179869187 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47244640267 47244640267 "
        "47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 "
        "47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 47244640267 "
        "47244640267 47244640267 47244640267 47244640267 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 "
        "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2199023255553 549755814144 2199023255680 42949672976 68719477248 4294967312 "
        "4294967297 1 0 145135534866432 32768 4294967297 4294967297 4294967297 0 8589934594 1 0 0 0 0 0 0 0 0 "
        "1099511627777 2199023255808 1099511628288 42949673216 1099511627904 8589934608 8589934593 1 0 140737488355328 "
        "131072 4294967297 4294967297 4294967297 0 8589934594 1 0 0 0 0 0 0 0 0 51539607553 17179934720 51539607556 "
        "34359803904 1099511627792 4294967304 4294967312 8 4294967296 565148976676864 16384 4294967297 4294967297 "
        "4294967297 0 8589934594 1 0 0 0 0 0 0 0 0 ";
    std::vector<size_t> expectWorkspaces = {35158016};
    ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces);
}
